from django import template
register = template.Library()

def status_options():
    return {"statuses": [(1, "approved"), (2, "deleted")]}

def jrc_test(value):
    return value + "XXX"

def jrc_intformat(value):
    # Take before comma
    value = str(value)
    if len(value) < 1:
        return ""
    
    # Store '-' if any
    sign = ""
    try:
        if value.startswith("-"):
            sign = "-"
            value = value[1:]
#            print "W/o minus sign: %s" % value 
        
        parts = value.split(".")
#        print "Real and decimal: %s" % parts
        
        value = str(parts[0])
        if len(value) < 4:
            value = value
        else:
            # Split number by 3 from the end of string
            ar = []
            while value:
                ar.append(value[-3:])
                value = value[:-3]
        
            ar.reverse()
            value = ",".join(ar)
    
        if len(parts) > 1:
            value = "%s.%s" % (value, parts[1][:2])
    
    except:
        print "Error formating %s!" % value
#    print "Value w/ sign: %s%s" % (sign, value)
    return "%s%s" % (sign, value)

register.filter("jrc_intformat", jrc_intformat)
#register.inclusion_tag("status_options.html")(status_options)
#register.filter("jrctest", jrc_test)
